#undef unicode
#include <irrlicht.h>
#include <IMeshBuffer.h>
#include <windows.h>
#include <iostream>
#include <vector>
using namespace irr;


int main()
 {
        // start up the engine
        IrrlichtDevice *device = createDevice(video::EDT_OPENGL,
                core::dimension2d<u32>(940,730));

        video::IVideoDriver* driver = device->getVideoDriver();
        scene::ISceneManager* scenemgr = device->getSceneManager();
        device->getCursorControl()->setVisible(false);
        device->setWindowCaption(L"Base Space World");


        // add a first person shooter style user controlled camera
        scene::ICameraSceneNode* camera = scenemgr->addCameraSceneNodeFPS();
		camera->setPosition(core::vector3df(0,0,50));
		camera->setTarget(core::vector3df(0,0,0));
		



		core::aabbox3d<f32> Box;
		video::SMaterial Material;
		Material.Wireframe = false;
		Material.Lighting = false;



		irr::scene::SMesh* mymesh;
 
		mymesh = new irr::scene::SMesh();
		
		irr::scene::SMeshBuffer *buf = 0;
		buf = new irr::scene::SMeshBuffer();
		mymesh->addMeshBuffer(buf);
		buf->drop();
		
		std::cout << "Buffer created.\n";
		
		buf->Vertices.set_used(0);
		buf->Vertices.push_back( video::S3DVertex(0,0,10, 1,1,0,    video::SColor(255,0,255,255), 0, 1));
		buf->Vertices.push_back( video::S3DVertex(10,0,-10, 1,0,0,  video::SColor(255,255,0,255), 1, 1));
		buf->Vertices.push_back( video::S3DVertex(0,20,0, 0,1,1,    video::SColor(255,255,255,0), 1, 0));
		buf->Vertices.push_back( video::S3DVertex(-10,0,-10, 0,0,1, video::SColor(255,0,255,0), 0, 0));
		std::cout << "Vertices created.\n";
				
		buf->Indices.set_used(0);
		buf->Indices.push_back(0);
		buf->Indices.push_back(2);
		buf->Indices.push_back(3);
		buf->Indices.push_back(2);
		buf->Indices.push_back(1);
		buf->Indices.push_back(3);
		buf->Indices.push_back(1);
		buf->Indices.push_back(0);
		buf->Indices.push_back(3);
		buf->Indices.push_back(2);
		buf->Indices.push_back(0);
		buf->Indices.push_back(1);
		std::cout << "Indices created.\n";

		buf->getMaterial() = Material;


		std::cout << "Adding to scene\n";

		buf->recalculateBoundingBox();
		irr::scene::IMeshSceneNode* node = scenemgr->addMeshSceneNode( mymesh );


        // draw everything
        u32 then = device->getTimer()->getTime();
        while(device->run() && driver)
        {
				if (device->isWindowActive())
				{
					//work out delta
					const u32 now = device->getTimer()->getTime();
					const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
					then = now;
					
					//Planet::Move_Planets(frameDeltaTime);
					driver->beginScene(true, true, video::SColor(255,0,0,200));
					scenemgr->drawAll();
					
					
					driver->endScene();
				}else then = device->getTimer()->getTime();
        }

        // delete device
        device->drop();
        return 0;
 }
